﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Core.Log;

namespace Core.Xml.Ogc.Ows
{
    class ContactType : IXmlType
    {
        public TelephoneType Phone { get; set; }
        public AddressType Address { get; set; }
        public OnlineResourceType OnlineResource { get; set; }
        public String HoursOfService { get; set; }
        public String ContactInstructions { get; set; }

        public XElement CreateXElement(XName elementName)
        {
            XElement contact = new XElement(elementName);
            
            bool check = true;
            
            if (Phone != null)
            {
                contact.Add(Phone.CreateXElement(Namespaces.OWS + "Phone"));
                check = true;
            }
            if (Address != null)
            {
                contact.Add(Address.CreateXElement(Namespaces.OWS + "Address"));
                check = true;
            }
            if (OnlineResource != null)
            {
                contact.Add(Namespaces.OWS + "OnlineResource", OnlineResource);
                check = true;
            }
            if (!String.IsNullOrEmpty(HoursOfService))
            {
                contact.Add(Namespaces.OWS + "HoursOfService", HoursOfService);
                check = true;
            }
            if (!String.IsNullOrEmpty(ContactInstructions))
            {
                contact.Add(Namespaces.OWS + "ContactInstructions", ContactInstructions);
                check = true;
            }
            
            if (!check)
                Logger.GetInstance().Add(new BasicLog(LogPriority.WARNING, "Contact Type element is empty, it should be removed."));

            return contact;
        }
    }
}
